﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using BookSystem;

namespace BookSystem.Admin
{
    public partial class Borrow : Form
    {
        public Borrow()
        {
            InitializeComponent();
        }

        SqlConnection conn = CommomHelper.SQLHelper.getConnnection();



        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {

                textBox1.Enabled = true;

            }
            else
            {

                textBox1.Enabled = false;
                textBox1.Text = "";

            }

        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {

                textBox2.Enabled = true;

            }
            else
            {

                textBox2.Enabled = false;
                textBox2.Text = "";

            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {

                textBox1.Enabled = textBox2.Enabled = false;

            }
         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlDataReader dr;
            string str_cmd = "";

            if (radioButton1.Checked && textBox1.Text.Trim() != null)
            {

                str_cmd = "select u.Uid,u.Uname,b.Bid,b.Bname,b.Bpress,b.Author, br.date from T_user as u,T_books as b, T_brrow as br where b.Bid = br.Bid and u.Uid = br.Uid and b.Bname like '" + textBox1.Text + "%'";

            }
            else if (radioButton2.Checked && textBox1.Text.Trim() != null)
            {


                str_cmd = "select u.Uid,u.Uname,b.Bid,b.Bname,b.Bpress,b.Author, br.date from T_user as u,T_books as b, T_brrow as br where b.Bid = br.Bid and u.Uid = br.Uid and u.Uname like '" + textBox2.Text + "%'";

            }
            else if (radioButton3.Checked)
            {


                str_cmd = "select u.Uid,u.Uname,b.Bid,b.Bname,b.Bpress,b.Author, br.date from T_user as u,T_books as b, T_brrow as br where b.Bid = br.Bid and u.Uid = br.Uid ";

            }
            else
            {

                MessageBox.Show("请再检查一遍检索输入", "温馨提示");
                return;
            }



            //执行语句
            SqlCommand cmd = new SqlCommand(str_cmd, conn);
            dr = cmd.ExecuteReader();

            //提前清空数据
            listView1.Items.Clear();

            if (dr.HasRows)
            {

                while (dr.Read())
                {

                    ListViewItem item = new ListViewItem();

                    item.Text = dr[0].ToString();
                    item.SubItems.Add(dr.GetString(1));
                    item.SubItems.Add(dr.GetString(2));
                    item.SubItems.Add(dr.GetString(3));
                    item.SubItems.Add(dr.GetString(4));
                    item.SubItems.Add(dr.GetString(5));
                    item.SubItems.Add(dr.GetString(6));
                    listView1.Items.Add(item);

                }
                dr.Close();
            }
            else
            {
                dr.Close();
                MessageBox.Show("没有满足条件的记录", "温馨提示");



            }

        }

        private void Borrow_FormClosed(object sender, FormClosedEventArgs e)
        {
            conn.Close();
        }



       



  
    }
}
